#include "Score.h"
#include "ColorText.h"
#include <sstream>

Score::Score()
    : BackgroundColor(Area(20, 20, 100, 200), Color(0, 0, 0, 150)), nextTextPos(0)
{
}

Score::~Score()
{
}

void Score::handleEvent(const Event& event)
{
    event.visitScore(this);
}

void Score::addPlayer(long textId, const std::string& name, const Color& color)
{
    addLine(new ColorText(Position(5, nextTextPos), color, name));
    addLine(new ColorText(textId, Position(5, nextTextPos), color, "0"));
}

void Score::updateScore(long textId, int score)
{
    Text* text = (Text*)findChild(textId);
    std::ostringstream scoreStr;
    scoreStr << score;
    text->setText(scoreStr.str());
}

void Score::addLine(Text* text)
{
    nextTextPos += text->getFontSize();
    addChild(text);
}
